package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

public class Practice10HistogramView extends View {

    private Paint mPaint;

    public Practice10HistogramView(Context context) {
        super(context);
    }

    public Practice10HistogramView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setColor(Color.WHITE);
    }

    public Practice10HistogramView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        综合练习
//        练习内容：使用各种 Canvas.drawXXX() 方法画直方图
        //坐标
        canvas.drawLine(100,50,100,400,mPaint);
        canvas.drawLine(100,400,650,400,mPaint);
        //文字
        mPaint.setColor(Color.WHITE);
        mPaint.setTextSize(24);
        canvas.drawText("GB",135,420,mPaint);
        canvas.drawText("IC S",210,420,mPaint);
        canvas.drawText("JB",290,420,mPaint);
        canvas.drawText("KitKat",360,420,mPaint);
        canvas.drawText("L",460,420,mPaint);
        canvas.drawText("M",540,420,mPaint);
        //柱状图
        mPaint.setColor(Color.GREEN);
        mPaint.setStyle(Paint.Style.FILL);
        canvas.drawRect(120,380,180,400,mPaint);
        canvas.drawRect(200,180,260,400,mPaint);
        canvas.drawRect(280,80,340,400,mPaint);
        canvas.drawRect(360,280,420,400,mPaint);
        canvas.drawRect(440,200,500,400,mPaint);
        canvas.drawRect(520,98,580,400,mPaint);
    }
}
